import 'package:flutter/material.dart';

/// @date 2020/08/05  10:08
/// @author 程志强
/// @des 颜色

class ColorRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("颜色"),
      ),
      body: Column(
        children: <Widget>[
          NavBar(color: Colors.white,title: "标题",),
          NavBar(color: Colors.blue,title: "标题",),
        ],
      ),
    );
  }
}

class NavBar extends StatelessWidget {
  final String title;
  final Color color;

  NavBar({this.title, this.color});

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints(minHeight: 52, maxWidth: double.infinity),
      decoration: BoxDecoration(color: this.color, boxShadow: [
        BoxShadow(color: Colors.black26, offset: Offset(0, 3), blurRadius: 3)
      ]),
      child: Text(
        this.title,
        style: TextStyle(
            fontWeight: FontWeight.bold,
            // 根据背景色亮度来确认Title颜色
            color:
                this.color.computeLuminance() < 0.5 ? Colors.white : Colors.black),
      ),
      alignment: Alignment.center,
    );
  }
}
